//声明: 该文件需要 jquery

require(["config"], function(config) {
	require([ "jquery","swiper"], function(jq,swiper) {
		/*----top   下拉菜单----*/
		jq(".float-right-mykd").hover(function(){
			jq(".float-right-mykd ul").attr("class","show")
		},function(){
			jq(".float-right-mykd ul").attr("class","hide")
		})
		jq(".float-right-help").hover(function(){
			jq(".float-right-help ul").attr("class","show")
		},function(){
			jq(".float-right-help ul").attr("class","hide")
		})
		
		
		
		//商品分类

		$('.all-goods .item').hover(function(){
	
			$(this).addClass('active').find('s').hide();
	
			$(this).find('.product-wrap').show();
	
		},function(){
	
			$(this).removeClass('active').find('s').show();
	
			$(this).find('.product-wrap').hide();
	
		});
		/*------------newhot------------------*/
		jq(".tab1").hover(function(){
			jq(".ul1").show();
			jq(".ul2").hide();
			jq(".tab1 a").css({"background":"#fff"});
			jq(".tab2 a").css({"background":"#f4f4f4"});
		})
		jq(".tab2").hover(function(){
			jq(".ul2").show();
			jq(".ul1").hide();
			jq(".tab2 a").css({"background":"#fff"});
			jq(".tab1 a").css({"background":"#f4f4f4"});
		})
		
		/*-----------今日秒杀模块----------------*/
		jq("#todayms .todayms_con .todayleft .todayleft-a").hover(function(){
			jq(".todayright-a").css({"display":"block"});
			jq(".todayright-b").css({"display":"none"});
			jq(".todayleft-a a").css({"background-position-y":"0px"})
			jq(".todayleft-b a").css({"background-position-y":"-91px"})
			
			
		})
		jq("#todayms .todayms_con .todayleft .todayleft-b").hover(function(){
			jq(".todayright-a").css({"display":"none"});
			jq(".todayright-b").css({"display":"block"});
			jq("#todayms .todayms_con .todayleft .todayleft-a a").css({"background-position-y":"-182px"})
			jq("#todayms .todayms_con .todayleft .todayleft-b a").css({"background-position-y":"-273px"})
			
		})
		/*-------------1F小轮播图--------------------------*/
		var mySwiper = new Swiper(".swiper-container",{
		//	loop:true,
			autoplay:2000,
			paginationClickable :true,
			autoplayDisableOnInteraction : false,
		//	updateOnImagesReady : true,
			pagination: '.swiper-pagination'
		});
		
//		/*-----------------门店鼠标滑过效果------------------------*/
		jq("#index_shop .left li").each(function(){
			jq(this).hover(function(){
				jq(this).attr("class","map_on").siblings().attr("class","info")	
			})
		})
		jq(".tab li").each(function(){
			jq(this).hover(function(){
				jq(this).attr("class","on").siblings().attr("class","")	
				
			})
		})
		
		/*-----回到顶部-----------------------*/
		$(".pf_right_6").click(function() {
			$("body,html").animate({
					scrollTop: 0
				}, 500, function() {
				mark = 1;
			});
		});
		
		
		/*--------------加入购物车动画-----------------*/
		
		//获取Id
				var Box = document.getElementById("box");
				var Top = document.getElementById("Top");
				var admin = document.getElementById("appendCart");
				var btn = document.getElementById("btn");
				var bgbox = document.getElementById("bgbox");
				var Plist = document.getElementById("Plist");
				var buttons = document.getElementById("buttons")

				//单击×号退出登录
				Plist.onclick = function() {
					bgbox.style.display = "none";
				}

				//点击加入购物车弹出子窗口
				admin.onclick = function() {
					bgbox.style.display = "block";
				}
				buttons.onclick = function() {
					bgbox.style.display = "none";
				}
				//窗口拖拽效果
				Top.onmousedown = function(e) {
					var e = e || event;
					var mousex = e.offsetX;
					var mousey = e.offsetY;
					document.onmousemove = function(e) {
						var e = e || event;
						var _left = e.clientX - mousex;
						var _top = e.clientY - mousey;
						if(_left < 0) {
							_left = 0
						}
						if(_top < 0) {
							_top = 0;
						}
						if(_left > (bgbox.offsetWidth - Top.offsetWidth)) {
							_left =bgbox.offsetWidth - Top.offsetWidth;
						}
						if(_top>(bgbox.offsetHeight - Box.offsetHeight)) {
							_top=bgbox.offsetHeight - Box.offsetHeight;

						}

						Box.style.left = _left + "px";
						Box.style.top = _top + "px";

					}
				}
				document.onmouseup = function() {
					document.onmousemove = null;

				}
				/*-----------加入购物车结束---------------*/
		
		
		
		
		
		/*-----放大鏡部分------*/
		$(function(){
			$.fn.magnifying = function(){
				var that = $(this),
				 $imgCon = that.find('.con-fangDaIMg'),//正常图片容器
				 	$Img = $imgCon.find('img'),//正常图片，还有放大图片集合
				   $Drag = that.find('.magnifyingBegin'),//拖动滑动容器
				   $show = that.find('.magnifyingShow'),//放大镜显示区域
				$showIMg = $show.find('img'),//放大镜图片
				$ImgList = that.find('.con-FangDa-ImgList > li >img'),
				multiple = $show.width()/$Drag.width();
		
				$imgCon.mousemove(function(e){
					$Drag.css('display','block');
					$show.css('display','block');
				    //获取坐标的两种方法
				   	// var iX = e.clientX - this.offsetLeft - $Drag.width()/2,
				   	// 	iY = e.clientY - this.offsetTop - $Drag.height()/2,	
				   	var iX = e.pageX - $(this).offset().left - $Drag.width()/2,
				   		iY = e.pageY - $(this).offset().top - $Drag.height()/2,	
				   		MaxX = $imgCon.width()-$Drag.width(),
				   		MaxY = $imgCon.height()-$Drag.height();
						
		  	   	    /*这一部分可代替下面部分，判断最大最小值
				   	var DX = iX < MaxX ? iX > 0 ? iX : 0 : MaxX,
				   		DY = iY < MaxY ? iY > 0 ? iY : 0 : MaxY;
				   	$Drag.css({left:DX+'px',top:DY+'px'});	   		
				   	$showIMg.css({marginLeft:-3*DX+'px',marginTop:-3*DY+'px'});*/
		
				   	iX = iX > 0 ? iX : 0;
				   	iX = iX < MaxX ? iX : MaxX;
				   	iY = iY > 0 ? iY : 0;
				   	iY = iY < MaxY ? iY : MaxY;	
				   	$Drag.css({left:iX+'px',top:iY+'px'});	   		
				   	$showIMg.css({marginLeft:-multiple*iX+'px',marginTop:-multiple*iY+'px'});
				   	//return false;
				});
				$imgCon.mouseout(function(){
				   	$Drag.css('display','none');
					$show.css('display','none');
				});
		
				$ImgList.click(function(){
					var NowSrc = $(this).data('bigimg');
					$Img.attr('src',NowSrc);
					$(this).parent().addClass('active').siblings().removeClass('active');
				});	
			}
		
			$("#fangdajing").magnifying();
		
		
		});
		/*----------------放大镜结束-------------------*/
		
		

		
		
		
		
		
			
		
	});
})

		
	